package com.ant.storage.service.impl;

import com.ant.storage.dto.DictionaryDto;
import com.ant.storage.mapper.DictionaryMapper;
import com.ant.storage.pojo.Dictionary;
import com.ant.storage.service.IDictionaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author melon
 * @since 2022-03-16
 */
@Service
public class DictionaryServiceImpl extends ServiceImpl<DictionaryMapper, Dictionary> implements IDictionaryService {

    @Override
    public PageInfo<Dictionary> Pagelist(DictionaryDto dictionaryDto) {
        PageHelper.startPage(dictionaryDto.getPageIndex(), dictionaryDto.getPageSize());
        QueryWrapper<Dictionary> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotEmpty(dictionaryDto.getTypeCode())) {
            wrapper.lambda().eq(Dictionary::getTypeCode, dictionaryDto.getTypeCode());
        }
        wrapper.lambda().eq(Dictionary::getIsShow, 1);
        wrapper.orderByAsc("sort_no");
        PageInfo<Dictionary> info = new PageInfo<>(this.baseMapper.selectList(wrapper));
        return info;
    }

    @Override
    public List<Dictionary> findDictionaryType() {
        return this.baseMapper.findDictionaryType();
    }


}
